package org.csu.mybigpro.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import java.net.InetSocketAddress;
import java.net.Proxy;

@Configuration
public class AppConfig {

    @Bean
    @Primary // 将这个标记为默认的 Bean
    public RestTemplate restTemplate() {
        // [修复] 在这里统一配置代理，确保所有使用此Bean的服务都走代理
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890));
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setProxy(proxy);
        requestFactory.setConnectTimeout(30000); // 30秒连接超时
        requestFactory.setReadTimeout(60000);    // 60秒读取超时
        return new RestTemplate(requestFactory);
    }

    @Bean("InRestTemplate")
    public RestTemplate InRestTemplate() {
        return new RestTemplate();
    }




}